package com.hu.web.servlet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class FourthServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        System.out.println("FourthServlet: id=" + id + ",name=" + name);

        System.out.println("FourthServlet doGet 执行");

        // 作为域对象共享数据
        request.setAttribute("requestMsg","request共享的数据");

        // 通过转发,将请求转发到 FifthServlet
        RequestDispatcher fifthServlet = request.getRequestDispatcher("fifth"); // 填写的是 FifthServlet 的访问路径
        // 将 request 和 response 传递过去
        fifthServlet.forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }

}
